<template>
  <div class="uploadCourseDesign">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程设计</el-breadcrumb-item>
      <el-breadcrumb-item>查看课设安排</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20" class="mb-12">
      <el-col :span="5">
        <div class="">
          <el-select v-model="form.majorID" placeholder="请选择专业" class="max-width">
            <el-option
              v-for="item in major"
              :label="item.majorName"
              :value="item.majorID">
            </el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            v-model="form.grade"
            align="right"
            type="year"
            class="max-width"
            placeholder="请选择年级"
            @change="getGrade">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            v-model="form.academicYear"
            align="right"
            type="year"
            class="max-width"
            placeholder="请选择学年"
            @change="getAcademicYear">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-select v-model="form.term" placeholder="请选择学期">
            <el-option label="01" value="01"></el-option>
            <el-option label="02" value="02"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="overflow-clear">
          <el-button type="primary" class="add-pd-26 float-right" @click="searchCourse">搜索</el-button>
        </div>
      </el-col>
    </el-row>
    <el-table
      :data="courseInfo"
      style="width: 100%">
      <!--<el-table-column
        type="selection"
        width="55">
      </el-table-column>-->
       <el-table-column
        prop="courseDesignName"
        label="课设名称"
        min-width="140">
      </el-table-column>
      <el-table-column
        prop="courseNameCN"
        label="课程名称"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="teacherName"
        label="负责教师"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="className"
        label="班级"
        min-width="130">
      </el-table-column>
      <el-table-column
        prop="startTime"
        label="开始时间"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="endTime"
        label="结束时间"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="uploader"
        label="上传人"
        min-width="100">
      </el-table-column>
      <el-table-column
        label="课程设计安排"
        min-width="130">
        <template scope="scope">
          <el-button type="text" @click.native.prevent="showCourseArrangeInfo(scope.row.courseArrangeInfo)">
            {{scope.row.courseArrangeInfoName}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="课程设计内容"
        min-width="130">
        <template scope="scope">
          <el-button type="text" @click.native.prevent="showCourseDesignInfo(scope.row.courseDesignInfo)">
            {{scope.row.courseDesignInfoName}}
          </el-button>
        </template>
      </el-table-column>
      
    </el-table>
    <div class="paging">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalPage">
      </el-pagination>
    </div>
  </div>
</template>

<script>
	//import pdfobject from '../../assets/js/pdfobject.js'
  export default {
    name: 'uploadCourseDesign',
    data() {
      return {
        form: {
          majorID: '',
          grade: '',
          academicYear: '',
          term: '',
        },
        courseInfo: [{
        	courseDesignerName:'',
          courseNameCN: 'java',
          teacherName: '翁自觉',
          className: '软件132003班',
          startTime: '2016-03-01',
          endTime: '2016-03-15',
          uploader: '翁自觉',
          courseArrangeInfoName: '课程设计安排',
          courseDesignInfoName: '课程设计内容',
          majorName: '软件工程',
          grade: '2013',
          academicYear: '2016',
          term: '1',
          //不需要显示
          courseDesignID: '',        //课程设计ID
          courseArrangeInfoStore: '',    // 课程设计安排路径
          courseDesignInfoStore: '' ,//课程设计内容路径
          courseArrangeInfo:'',
          courseDesignInfo:''

        },
          {
            courseNameCN: 'oracle数据库',
            teacherName: '谢斌红',
            className: '软件132003班',
            startTime: '2017-03-01',
            endTime: '2017-03-15',
            uploader: '谢斌红',
            majorName: '软件工程',
            grade: '2013',
            academicYear: '2017',
            term: '1'
          }],
        major: [],
        pagingCourseInfo: [],
        totalPage: 20,
        currentPage: 1,
        pageSizes: [10, 20, 30, 40],
        pageSize: 10,
        searchStatus: 0,
      }
    },
    created () {
      this.res();
      this.getMajor();
    },
    methods: {
      submitUpload() {
        this.$refs.upload.submit();
      },
      res: function () {
        this.$http.get(`${this.$until.url}/courseDesign/getCourseDesignT`,
          {//请求参数
            params: {
              page: this.currentPage,
              pageSize: this.pageSize,
              teacherID:'01'
            }
          })
          .then((res) => {
            // 响应成功回调
            this.courseInfo = res.body.info
            this.totalPage = res.body.num.num
            console.log(res)
          }, (err) => {
            // 响应错误回调
            //console.log(err)
          })
      },
      getMajor(){
        this.$http.get(`${this.$until.url}/courseDesign/getMajorDesign`)
          .then((res) => {
            //console.log(res)
            this.major = res.body
          }, (err) => {
            // 响应错误回调
            //console.log(err)
          })
      },
      showCourseArrangeInfo(courseArrangeInfoStore){
        window.open(`${this.$until.url}/${courseArrangeInfoStore}`)
        //console.log(courseArrangeInfoStore)
      },
      showCourseDesignInfo(courseDesignInfoStore){
        window.open(`${this.$until.url}/${courseDesignInfoStore}`)
        //console.log(courseArrangeInfoStore)
        /*this.$nextTick(() => {
        	var myPDF = new Pdfobject({ url: `${this.$until.url}/${courseDesignInfoStore}` }).embed();
        })*/
      },
      
      handleSizeChange(val) {
        //console.log(`每页 ${val} 条`);
        this.pageSize = val
        if (this.searchStatus == 1) {
          this.searchCourse()
        } else {
          this.res()
        }
      },
      handleCurrentChange(val) {
        //console.log(`当前页: ${val}`);
        this.currentPage = val;
        if (this.searchStatus == 1) {
          this.searchCourse()
        } else {
          this.res()
        }
      },
      getGrade(val){
        this.form.grade = val
      },
      getAcademicYear(val){
        this.form.academicYear = val
      },
      searchCourse() {
        this.searchStatus = 1
        this.$http.post(`${this.$until.url}/courseDesign/getCourseDesignT`, this.form,
          {//请求参数
            params: {
              page: this.currentPage,
              pageSize: this.pageSize,
              teacherID:'01'
            },
            emulateJSON: true
          })
          .then((res) => {
            //console.log(res)
            this.courseInfo = res.body.info
            this.totalPage = res.body.num.num
          }, (err) => {
            // 响应错误回调
            console.log('服务器异常')
          })
      },
      
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
